from abc import ABC, abstractmethod
from typing import List

from PySide6.QtWidgets import QWidget, QMainWindow


class BaseVisualizer(ABC):
    """
    可视化器的基础接口，所有具体可视化器必须实现这些方法
    """

    def __init__(self):
        """初始化可视化器"""
        pass

    @abstractmethod
    def load_file(self, file_path: str) -> bool:
        """
        加载文件

        Args:
            file_path: 文件路径

        Returns:
            bool: 加载是否成功
        """
        raise NotImplementedError("子类必须实现load_file方法")

    @abstractmethod
    def create_widget(self, main_window:QMainWindow):
        """

        子类要将创建的可视化内容挂载到main_window上

        Returns:
            QWidget: 可视化内容的widget
        """
        raise NotImplementedError("子类必须实现create_widget方法")


# 可视化策略接口
class VisualizationStrategy:
    def visualize(self, data, context):
        raise NotImplementedError


# 基础可视化组件
class VisualizationComponent:
    def __init__(self):
        self.strategies: List[VisualizationStrategy] = []

    def add_strategy(self, strategy: VisualizationStrategy):
        self.strategies.append(strategy)

    def visualize(self, data, context):
        for strategy in self.strategies:
            strategy.visualize(data, context)
